﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Activity>
@{
    this.ViewBag.Title = "Netværk";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Profiles = this.ViewData["Profiles"] as List<Profile>;
    var Locations = this.ViewData["Locations"] as List<Location>;
    var Presentations = this.ViewData["Presentations"] as List<Presentation>;
}

<div class="float-right smallMarginBottom">
    <input type="button" onclick="@string.Format("location.href = '{0}';", this.Url.Action("NewNetwork"))" value="Opret ny" class="" />
</div>

<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td>
    </tr>
    @if (this.Model != null)
    {
        foreach (Activity act in this.Model.List)
        {
            Profile organizer = Profiles.SingleOrDefault(x => x.ID == act.NA.Organizer);
            List<Location> locs = Locations.Where(x => x.ID == act.Location).ToList();
            Location location = locs.Count() > 0 ? Locations[0] : null;
            IEnumerable<Presentation> presList = Presentations.Where(x => act.NA.Presentations.Contains(x.ID));

        <tr>
            <td>@string.Format("{0:dd-MM-yyyy}", act.TimeOfActivity)</td>
            <td>
                @if (location != null)
                {
                    @location.Name
                }

            </td>
            <td>@act.NA.Attendance</td>
            <td>
                @if (organizer != null)
                {
                    @organizer.Name
                }
            </td>
            <td>
                @act.NA.ProductType
            </td>
            <td style="font-size: 0.7em;">

                @if (presList != null)
                {
                    @Html.Raw(string.Join(",<br/>", presList.Select(x => x.Name)))
                }
            </td>
            <td>
                <a href="@Url.Action("UpdateNetwork", new { @Id = act.ID })">
                    <img src="@Url.Content("~/Content/ButtonIcons/tool_blue.png")" alt="Link"/></a>
            </td>
        </tr>
        }
    }


    <tr>
        @Html.Partial("~/Views/_Shared/PagingArrows.cshtml", new PagingArrows { Action = "Index", TotalAmountOfColumns = 7, CurrentSkip = this.Model.Skip, CurrentTake = this.Model.Take, CurrentTotalRowCount = this.Model.TotalRows })
    </tr>
</table>
